#!python
import sys

def run_cli():
    from scheduler.cli import cli
    cli()
    
def run_server():
    from scheduler.server import run
    import argparse
    parser = argparse.ArgumentParser(description="Run the Flask application with custom host and port.")
    parser.add_argument("--host", default="127.0.0.1", help="Host address to bind the server to")
    parser.add_argument("--port", type=int, default=12030, help="Port number to bind the server to")
    args = parser.parse_args()

    # 使用解析后的参数启动Flask应用
    run(host=args.host, port=args.port)

if __name__ == "__main__":
    # 默认开clint
    if "--server" in sys.argv:
        sys.argv.remove('--server') # 先删除标志位参数
        run_server()
    elif "--multiprocessing-fork" not in sys.argv:
        run_cli()
    # 识别到--server参数，开启服务器模式
    else:
        print("param: ", sys.argv)